from datetime import datetime
from routes import db


class VepParameter(db.Model):
    __tablename__ = 'vep_parameters'
    id = db.Column(db.Integer, primary_key=True)
    year = db.Column(db.Integer, nullable=False)
    vepName = db.Column(db.String(100), nullable=False)
    vepCity = db.Column(db.String(50), nullable=False)
    vepDistrict = db.Column(db.String(50), nullable=False)
    vepTown = db.Column(db.String(50), nullable=False)
    projectArea = db.Column(db.Float, nullable=True)
    directSalesRevenue = db.Column(db.Float, nullable=True)
    processedProductsRevenue = db.Column(db.Float, nullable=True)
    townArea = db.Column(db.Float, nullable=True)
    regulationServiceValue = db.Column(db.Float, nullable=True)
    tourismHealthRevenue = db.Column(db.Float, nullable=True)
    roomPrice = db.Column(db.Float, nullable=True)
    averageOccupancyRate = db.Column(db.Float, nullable=True)
    roomCount = db.Column(db.Integer, nullable=True)
    realEstateRevenue = db.Column(db.Float, nullable=True)
    dailyVisitorFlow = db.Column(db.Integer, nullable=True)
    perCapitaDailyConsumption = db.Column(db.Float, nullable=True)
    ticketPrice = db.Column(db.Float, nullable=True)
    creator = db.Column(db.String(50), nullable=False)
    updater = db.Column(db.String(50), nullable=False)
    created_at = db.Column(db.DateTime, default=datetime.utcnow)
    updated_at = db.Column(db.DateTime, default=datetime.utcnow, onupdate=datetime.utcnow)

    def to_dict(self):
        return {
            'id': self.id,
            'year': self.year,
            'vepName': self.vepName,
            'vepCity': self.vepCity,
            'vepDistrict': self.vepDistrict,
            'vepTown': self.vepTown,
            'projectArea': self.projectArea,
            'directSalesRevenue': self.directSalesRevenue,
            'processedProductsRevenue': self.processedProductsRevenue,
            'townArea': self.townArea,
            'regulationServiceValue': self.regulationServiceValue,
            'tourismHealthRevenue': self.tourismHealthRevenue,
            'roomPrice': self.roomPrice,
            'averageOccupancyRate': self.averageOccupancyRate,
            'roomCount': self.roomCount,
            'realEstateRevenue': self.realEstateRevenue,
            'dailyVisitorFlow': self.dailyVisitorFlow,
            'perCapitaDailyConsumption': self.perCapitaDailyConsumption,
            'ticketPrice': self.ticketPrice,
            'creator': self.creator,
            'updater': self.updater,
            'created_at': self.created_at.isoformat(),
            'updated_at': self.updated_at.isoformat()
        }

class VepResult(db.Model):
    __tablename__ = 'vep_results'
    id = db.Column(db.Integer, primary_key=True)
    year = db.Column(db.Integer, nullable=False)
    vepName = db.Column(db.String(100), nullable=False)
    vepCity = db.Column(db.String(50), nullable=False)
    vepDistrict = db.Column(db.String(50), nullable=False)
    vepTown = db.Column(db.String(50), nullable=False)
    vepResult = db.Column(db.Float, nullable=True)
    provisioningServices = db.Column(db.Float, nullable=True)
    regulatingServices = db.Column(db.Float, nullable=True)
    culturalServices = db.Column(db.Float, nullable=True)
    creator = db.Column(db.String(50), nullable=False)
    updater = db.Column(db.String(50), nullable=False)
    created_at = db.Column(db.DateTime, default=datetime.utcnow)
    updated_at = db.Column(db.DateTime, default=datetime.utcnow, onupdate=datetime.utcnow)

    def to_dict(self):
        return {
            'id': self.id,
            'year': self.year,
            'vepCity': self.vepCity,
            'vepDistrict': self.vepDistrict,
            'vepTown': self.vepTown,
            'vepResult': self.vepResult,
            'provisioningServices': self.provisioningServices,
            'regulatingServices': self.regulatingServices,
            'culturalServices': self.culturalServices,
            'creator': self.creator,
            'updater': self.updater,
            'created_at': self.created_at.isoformat(),
            'updated_at': self.updated_at.isoformat()
        }